#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 2e5+10;
int tr[N][26], cnt[N], sz, f[N], ans[N], id[N];
\

void add(const string& s, int i){
    int p = 0;
    for(auto c:s){
        int& nx = tr[p][c-'a'];
        if(!nx) nx = ++sz;
        p = nx;
    }
    cnt[p] = 1;
    id[i] = p;
}

void getfail(){
    queue<int> q;
    for (int i = 0; i < 26; ++i) {
        int v = tr[0][i];
        if(v) q.push(v);
    }
    while (!q.empty()){
        int u = q.front(); q.pop();
        for (int i = 0; i < 26; ++i) {
            int v = tr[u][i];
            if(v) f[v] = tr[f[u]][i], q.push(v);
            else tr[u][i] = tr[f[u]][i];
        }
    }
}

void query(const string& s){
    int p = 0;
    for(auto c:s){
        p = tr[p][c-'a'];
        for (int i = p; i && ~cnt[i] ; i = f[i]) {
            ans[i] += cnt[i];
//            ans += cnt[i];
//            cnt[i] = -1;
        }
    }
//    return ans;
}



int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        add(s, i);
    }
    getfail();
    string s; cin >> s;
    query(s);
    for (int i = 0; i < n; ++i) {
        cout << ans[id[i]] << '\n';
    }
    return 0;
}